package com.jasonchoi.gateway;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @Author: JasonChoi
 * @Date: 2019/12/17 15:47
 */
@Configuration
public class RouteLocatorConfig {
    /**
     * 代码的方式配置gateweay路由
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        System.out.println("============================RouteLocatorConfig "+ builder.routes());
        return builder
                .routes()
                .route(r -> r.path("/*")
                             .filters(f -> f.filter(new LimitFilter(1,
                                     1, Duration.ofSeconds(1))))
                             .uri("lb://EUREKAPRODUCT")
                             .order(0)
                             .id("user_route"))
                .build();
    }
}